package com.xinyu.vo;

import com.fasterxml.jackson.annotation.JsonAlias;
import lombok.Data;

/**
 * Normalizes pagination params coming from different components (page/pageNum/currentPage, rows/pageSize, etc.).
 */
@Data
public class PageRequest {

    @JsonAlias({"page", "pageNum", "currentPage"})
    private Integer pageNum;

    @JsonAlias({"rows", "row", "pageSize"})
    private Integer pageSize;

    public int getSafePageNum() {
        if (pageNum == null || pageNum < 1) {
            return 1;
        }
        return pageNum;
    }

    public int getSafePageSize() {
        if (pageSize == null || pageSize < 1) {
            return 10;
        }
        return Math.min(pageSize, 200);
    }
}
